package Thread;

import java.util.concurrent.CountDownLatch;

/**
 * @Title: Demo7
 * @Author 郑雨杭
 * @Package Thread
 * @Date 2024/7/7 14:17
 * @description:
 */
public class Demo7 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "==>正在执行任务");
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println(Thread.currentThread().getName() + "==>任务执行完毕");
                    countDownLatch.countDown();
                }
            }, "T" + i);
            t.start();
        }
        System.out.println("任务执行完成了吗？");
        countDownLatch.await();
        System.out.println("任务执行完成了");

    }
}
